package com.wealth.scsj.b_app.model;

import com.wealth.scsj.b_app.base.GetOrderIncomeAndOrderQuantityBase;
import com.wealth.scsj.b_app.base.UpdateUserProfilePictureBase;
import com.wealth.scsj.b_app.bean.StoreOperationMainBean;
import com.wealth.scsj.b_app.bean.UpdateUserProfilePictureBean;

import dkmvp.net.ResponseCallback;
import dkmvp.net.ResponseHandler;
import dkmvp.net.RetryWithDelay;
import okhttp3.RequestBody;
import rx.Observable;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.schedulers.Schedulers;

/**
 * 门店运营--首页  获取今日收入 及 今日订单量
 */

public class GetOrderIncomeAndOrderQuantityModel extends BaseModel implements GetOrderIncomeAndOrderQuantityBase.IModel {

    @Override
    public Subscription getOrderIncomeAndOrderQuantity(RequestBody requestBody, final ResponseCallback<StoreOperationMainBean> callback) {
        Observable<StoreOperationMainBean> observable = service.GetOrderIncomeAndOrderQuantity(requestBody);
        Subscription sub = observable.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .retryWhen(new RetryWithDelay(3, 3000))//总共重试3次，重试间隔3秒
                .subscribe(new Action1<StoreOperationMainBean>() {
                    @Override
                    public void call(StoreOperationMainBean result) {
                        callback.onSuccess(result);
                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        callback.onFaild(ResponseHandler.getErrorMsg(throwable));
                    }
                });
        return  sub;
    }
}
